package com.example.myapplication;

import android.content.Context;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import ohos.ace.adapter.capability.bridge.BridgePlugin;

public class Bridge extends BridgePlugin {
    private AudioPlayer audioPlayer = new AudioPlayer();

    /**
     * @param context
     * @param bridgeName
     * @param instanceId
     * @deprecated
     */
    public Bridge(Context context, String bridgeName, int instanceId) {
        super(context, bridgeName, instanceId);
    }

    public String playMusic(Object object) {
        String s = object.toString();
        JSONObject json = JSON.parseObject(s);
        String path = json.getString("path");
        Log.e("HiHelloWorld", "playMusic " + path);
        audioPlayer.play(path);
        return json.getString("title");
    }

    public String stop(Object object) {
        audioPlayer.stop();
        return "success";
    }
}